package com.a3dweijing.wetouch2.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.a3dweijing.wetouch2.Common.CallBack;
import com.a3dweijing.wetouch2.Common.listview.CommonListviewAdapter;
import com.a3dweijing.wetouch2.Common.listview.ViewHolderListview;
import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.Util.GlideUtil;
import com.a3dweijing.wetouch2.bean.OrderListBean;
import com.a3dweijing.wetouch2.bean.PendingPaymentMsg;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by Administrator on 2018/3/29.
 */

public class OrderAdapter extends CommonListviewAdapter
{
    private CallBack callBack;
    
    public OrderAdapter(Context context, List list, int layoutId, CallBack callBack)
    {
        super(context, list, layoutId);
        this.callBack = callBack;
    }
    
    @Override
    public void convert(ViewHolderListview holder, Object o, int position)
    {
        OrderListBean item = (OrderListBean)o;
        ImageView imageView = holder.getView(R.id.imageview);
        TextView goods_name = holder.getView(R.id.goods_name);
        TextView type = holder.getView(R.id.type);
        TextView number = holder.getView(R.id.number);
        TextView all_money = holder.getView(R.id.all_money);
        RelativeLayout refund = holder.getView(R.id.refund);
        RelativeLayout delivergoods = holder.getView(R.id.delivergoods);
        RelativeLayout look_logistics = holder.getView(R.id.look_logistics);
        RelativeLayout confirm = holder.getView(R.id.confirm);
        RelativeLayout cancelOrder = holder.getView(R.id.cancel_order);
        RelativeLayout pay = holder.getView(R.id.pay);
        GlideUtil.getInstance().showImage(context, item.getGoods_imgurl(), imageView);
        goods_name.setText(item.getGoods_name());
        number.setText("一共" + item.getGoods_number() + "件商品");
        all_money.setText("￥" + item.getOrder_total() + "");
        String typeName = PendingPaymentMsg.getTypeName(item.getOrder_state());
        type.setText(typeName);
        refund.setVisibility(View.GONE);
        delivergoods.setVisibility(View.GONE);
        look_logistics.setVisibility(View.GONE);
        confirm.setVisibility(View.GONE);
        cancelOrder.setVisibility(View.GONE);
        pay.setVisibility(View.GONE);
        
        switch (item.getOrder_state())
        {
            case 1:
                cancelOrder.setVisibility(View.VISIBLE);
                setTextButton(cancelOrder);
                pay.setVisibility(View.VISIBLE);
                setTextButton(pay);
                break;
            case 2:
                delivergoods.setVisibility(View.VISIBLE);
                setTextButton(delivergoods);
                break;
            case 3:
                look_logistics.setVisibility(View.VISIBLE);
                setTextButton(look_logistics);
                confirm.setVisibility(View.VISIBLE);
                setTextButton(confirm);
                break;
            case 4:
            case 5:
                refund.setVisibility(View.VISIBLE);
                setTextButton(refund);
                break;
        }
    }
    
    private void setTextButton(View view)
    {
        TextView viewById = view.findViewById(R.id.infotv);
        viewById.setText(PendingPaymentMsg.getOperableName(view.getId()));
    }
}
